/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.servinf.ani.validadorani.gui;

import com.servinf.ani.validadorani.utils.Layers;
import com.servinf.ani.validadorani.validator.Validator;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration; 
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.WindowConstants;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.styling.Style;
import org.geotools.map.MapContent;
import org.geotools.styling.SLD;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;

/**
 *
 * 
 * @author mortiz
 */
public class MainGUI extends javax.swing.JFrame {

    private File shapeFile;
    private Map<JRadioButton, String> radioValuesMap;
    /**
     * Creates new form MainGUI
     */
    public MainGUI() {
        initComponents();
        setLocationRelativeTo(null);
        //jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/images.png"))); 
        helpBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/images.png"))); 
        resultIcon = null;
        
        radioValuesMap = new HashMap<JRadioButton, String>();
        
        layerTypes.add(radioTramo);
        radioValuesMap.put(radioTramo, Layers.TRAMO_VIA);
        
        layerTypes.add(radioBerma);
        radioValuesMap.put(radioBerma, Layers.BERMA);
        
        layerTypes.add(radiodanoAfirmado);
        radioValuesMap.put(radiodanoAfirmado, Layers.DANOAFIRMADO);
        
        layerTypes.add(radioDAniRigido);
        radioValuesMap.put(radioDAniRigido, Layers.DANORIGIDO);
        
        layerTypes.add(radioDanoFlexible);
        radioValuesMap.put(radioDanoFlexible, Layers.DANOFLEXIBLE);
        
        layerTypes.add(radioEstacionPesaje);
        radioValuesMap.put(radioEstacionPesaje, Layers.ESTACIONPESAJE);
        
        layerTypes.add(radioInterseccion);
        radioValuesMap.put(radioInterseccion, Layers.INTERSECCION);
        
        layerTypes.add(radioMuro);
        radioValuesMap.put(radioMuro, Layers.MURO);
        
        layerTypes.add(radioPeaje);
        radioValuesMap.put(radioPeaje, Layers.PEAJE);
        
        layerTypes.add(radioPuente);
        radioValuesMap.put(radioPuente, Layers.BERMA);
        
        layerTypes.add(radioSeccionTransversal);
        radioValuesMap.put(radioSeccionTransversal, Layers.SECCIONTRANSVERSAL);
        
        layerTypes.add(radioSenalHorizontal);
        radioValuesMap.put(radioSenalHorizontal, Layers.SENALHORIZONTAL);
        
        layerTypes.add(radioSenalVertical);
        radioValuesMap.put(radioSenalVertical, Layers.SENALVERTICAL);
        
        layerTypes.add(radioSeparador);
        radioValuesMap.put(radioSeparador, Layers.SEPARADOR);
        
        layerTypes.add(radioSitioAccidentalidad);
        radioValuesMap.put(radioSitioAccidentalidad, Layers.SITIOCRITICOACCIDENTALIDAD);
        
        layerTypes.add(radioSitioInestabilidad);
        radioValuesMap.put(radioSitioInestabilidad, Layers.SITIOCRITICOINESTABILIDAD);
        
        layerTypes.add(radioTipoTerreno);
        radioValuesMap.put(radioTipoTerreno, Layers.TIPOTERRENO);
        
        layerTypes.add(radioTunel);
        radioValuesMap.put(radioTunel, Layers.TUNEL);
        
        
        helpBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpBtnActionPerformed(evt);
            }
        });
        
    }

    private void helpBtnActionPerformed(java.awt.event.ActionEvent evt) {
        JOptionPane.showMessageDialog(this, "Si habilita esta opción se validará que los campos que son obligatorios, \n "
                + "tengan dicha restricción en los atributos de la capa ");
    }
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        layerTypes = new javax.swing.ButtonGroup();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        filePathText = new javax.swing.JTextField();
        openFileChooserBtn = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        radioTramo = new javax.swing.JRadioButton();
        jLabel4 = new javax.swing.JLabel();
        radioBerma = new javax.swing.JRadioButton();
        radioSeccionTransversal = new javax.swing.JRadioButton();
        radioSeparador = new javax.swing.JRadioButton();
        radioTipoTerreno = new javax.swing.JRadioButton();
        radioPuente = new javax.swing.JRadioButton();
        radioMuro = new javax.swing.JRadioButton();
        radioTunel = new javax.swing.JRadioButton();
        radioEstacionPesaje = new javax.swing.JRadioButton();
        radioInterseccion = new javax.swing.JRadioButton();
        radioPeaje = new javax.swing.JRadioButton();
        radioSitioAccidentalidad = new javax.swing.JRadioButton();
        radioSitioInestabilidad = new javax.swing.JRadioButton();
        radioSenalHorizontal = new javax.swing.JRadioButton();
        radioSenalVertical = new javax.swing.JRadioButton();
        radioDanoFlexible = new javax.swing.JRadioButton();
        radioDAniRigido = new javax.swing.JRadioButton();
        radiodanoAfirmado = new javax.swing.JRadioButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        outputTextArea = new javax.swing.JTextArea();
        validateBtn = new javax.swing.JButton();
        resultIcon = new javax.swing.JLabel();
        resultText = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        showShapeBtn = new javax.swing.JButton();
        resultIcon1 = new javax.swing.JLabel();
        validateMandatoryCheck = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        helpBtn = new javax.swing.JButton();

        jButton2.setText("jButton2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("VALIDADOR DE CAPAS ANI");

        filePathText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                filePathTextActionPerformed(evt);
            }
        });

        openFileChooserBtn.setText("Seleccionar Archivo");
        openFileChooserBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openFileChooserBtnActionPerformed(evt);
            }
        });

        jLabel3.setText(" Cargue el shape que desea validar");

        radioTramo.setSelected(true);
        radioTramo.setText("01_TRAMOVIA");
        radioTramo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioTramoActionPerformed(evt);
            }
        });

        jLabel4.setText("Tipo de capa");

        radioBerma.setText("02_BERMA");

        radioSeccionTransversal.setText("03_SECCIONTRANSVERSAL");

        radioSeparador.setText("04_SEPARADOR");

        radioTipoTerreno.setText("05_TIPOTERRENO");

        radioPuente.setText("06_PUENTE");

        radioMuro.setText("07_MURO");

        radioTunel.setText("08_TUNEL");

        radioEstacionPesaje.setText("09_ESTACIONPESAJE");

        radioInterseccion.setText("10_INTERSECCION");

        radioPeaje.setText("11_PEAJE");

        radioSitioAccidentalidad.setText("12_SITIOCRITICOACCIDENTALIDAD");

        radioSitioInestabilidad.setText("13_SITIOCRITICOINESTABILIDAD");

        radioSenalHorizontal.setText("14_SENALHORIZONTAL");
        radioSenalHorizontal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioSenalHorizontalActionPerformed(evt);
            }
        });

        radioSenalVertical.setText("15_SENALVERTICAL");

        radioDanoFlexible.setText("16_DANOFLEXIBLE");

        radioDAniRigido.setText("17_DANORIGIDO");

        radiodanoAfirmado.setText("18_DANOAFIRMADO");

        outputTextArea.setColumns(20);
        outputTextArea.setRows(5);
        outputTextArea.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jScrollPane1.setViewportView(outputTextArea);

        validateBtn.setText("Validar");
        validateBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                validateBtnActionPerformed(evt);
            }
        });

        resultText.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        jButton1.setText("Limpiar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        showShapeBtn.setText("Ver Shape");
        showShapeBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showShapeBtnActionPerformed(evt);
            }
        });

        validateMandatoryCheck.setText("Validar obligatoriedad de los campos");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(resultIcon)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(resultIcon1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(resultText, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 674, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(openFileChooserBtn)
                                        .addGap(3, 3, 3)
                                        .addComponent(filePathText, javax.swing.GroupLayout.PREFERRED_SIZE, 546, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(radioSeccionTransversal)
                                                        .addComponent(radioTramo)
                                                        .addComponent(radioBerma)
                                                        .addComponent(radioSeparador))
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                                .addGroup(layout.createSequentialGroup()
                                                    .addComponent(radioTipoTerreno)
                                                    .addGap(44, 44, 44)))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(radioPuente)
                                                .addGap(78, 78, 78)))
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(radioPeaje)
                                            .addComponent(radioInterseccion)
                                            .addComponent(radioTunel)
                                            .addComponent(radioMuro)
                                            .addComponent(radioEstacionPesaje)
                                            .addComponent(radioSitioAccidentalidad))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(radiodanoAfirmado)
                                            .addComponent(radioSenalVertical)
                                            .addComponent(radioDanoFlexible)
                                            .addComponent(radioDAniRigido)
                                            .addComponent(radioSenalHorizontal)
                                            .addComponent(radioSitioInestabilidad)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(validateBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(showShapeBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(validateMandatoryCheck)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(helpBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(49, 49, 49)
                                        .addComponent(jLabel5)))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel2))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(filePathText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(openFileChooserBtn))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radioTramo)
                    .addComponent(radioMuro)
                    .addComponent(radioSitioInestabilidad))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radioBerma)
                    .addComponent(radioTunel)
                    .addComponent(radioSenalHorizontal))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radioSeccionTransversal)
                    .addComponent(radioEstacionPesaje)
                    .addComponent(radioSenalVertical))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radioSeparador)
                    .addComponent(radioInterseccion)
                    .addComponent(radioDanoFlexible))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radioTipoTerreno)
                    .addComponent(radioPeaje)
                    .addComponent(radioDAniRigido))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(radioSitioAccidentalidad)
                        .addComponent(radiodanoAfirmado))
                    .addComponent(radioPuente))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(validateMandatoryCheck)
                        .addComponent(jLabel5)
                        .addComponent(helpBtn))
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                    .addComponent(validateBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(showShapeBtn, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(resultText, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(resultIcon1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(resultIcon, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void filePathTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filePathTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_filePathTextActionPerformed

    private void clean() {
        filePathText.setText("");
        resultIcon1.setIcon(null); 
        resultText.setText("");
        outputTextArea.setText("");
        shapeFile = null;
    }
    
    /**
     * Se ejecuta cuando se da clic en el botón de escoger archivo.
     * @param evt 
     */
    
    
    private void openFileChooserBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openFileChooserBtnActionPerformed
            clean();
            shapeFile = JFileDataStoreChooser.showOpenFile("shp", null);
            if (shapeFile == null) { 
                return;
            }
            filePathText.setText(shapeFile.getAbsolutePath());
    }//GEN-LAST:event_openFileChooserBtnActionPerformed

    private void radioTramoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioTramoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_radioTramoActionPerformed

    private void radioSenalHorizontalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioSenalHorizontalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_radioSenalHorizontalActionPerformed

    private void validateBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_validateBtnActionPerformed
        try {
            outputTextArea.setText("");
            if(shapeFile != null) {
                JRadioButton radioSelected = getSelectedRadioButton(layerTypes);
                String layerValue = radioValuesMap.get(radioSelected);
                FileDataStore store = FileDataStoreFinder.getDataStore(shapeFile);
                boolean hasValidStructure = Validator.validateStructure(store, layerValue, outputTextArea);
                if(!hasValidStructure) {
                    errorOutput();
                }else {
                    boolean hasValidDataTypes = Validator.validateDataTypes(store, layerValue, outputTextArea);
                    if(!hasValidDataTypes) {
                        errorOutput();
                    }else {
                        if(validateMandatoryCheck.isSelected()) {
                            boolean hasMandatoryFields = Validator.validateMandatoryFields(store, layerValue, outputTextArea);
                            if(!hasMandatoryFields) {
                                errorOutput();
                            }else {
                                successOutput();
                            }
                        }else {
                            successOutput();
                        }
                    }
                }
            }else {
                outputTextArea.append("No se ha seleccionado ningún archivo : \n");
            }
        } catch (IOException ex) {
            Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_validateBtnActionPerformed

    private void errorOutput() {
        resultIcon1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/error.png"))); 
        resultText.setText("El shape No es válido");
    }
    
    private void successOutput() {
        outputTextArea.append("El shape SI es válido");
        resultIcon1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/success.png"))); 
        resultText.setText("El shape es válido");
    }
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        clean();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void showShapeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showShapeBtnActionPerformed
        // Create a map content and add our shapefile to it
        MapContent map = new MapContent();
        if(shapeFile != null) {
            try {
                map.setTitle(shapeFile.getAbsolutePath());
                FileDataStore store = FileDataStoreFinder.getDataStore(shapeFile);
                SimpleFeatureSource featureSource = store.getFeatureSource();  
                Style style = SLD.createSimpleStyle(featureSource.getSchema());
                Layer layer = new FeatureLayer(featureSource, style);
                map.addLayer(layer);
                // Now display the map
                JMapFrame mapFrame = new JMapFrame();
                mapFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                mapFrame.setMapContent(map);
                JMapFrame.showMap(map);
            } catch (IOException ex) {
                Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }else {
            outputTextArea.setText("No se ha cargado ningún archivo .shp.");
        }
        
    }//GEN-LAST:event_showShapeBtnActionPerformed

    public JRadioButton getSelectedRadioButton(ButtonGroup buttonGroup) {
        for (Enumeration<AbstractButton> buttons = buttonGroup.getElements(); buttons.hasMoreElements();) {
            AbstractButton button = buttons.nextElement();
            if (button.isSelected()) {
                return (JRadioButton) button;
            }
        }
        return null;
    }
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField filePathText;
    private javax.swing.JButton helpBtn;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.ButtonGroup layerTypes;
    private javax.swing.JButton openFileChooserBtn;
    private javax.swing.JTextArea outputTextArea;
    private javax.swing.JRadioButton radioBerma;
    private javax.swing.JRadioButton radioDAniRigido;
    private javax.swing.JRadioButton radioDanoFlexible;
    private javax.swing.JRadioButton radioEstacionPesaje;
    private javax.swing.JRadioButton radioInterseccion;
    private javax.swing.JRadioButton radioMuro;
    private javax.swing.JRadioButton radioPeaje;
    private javax.swing.JRadioButton radioPuente;
    private javax.swing.JRadioButton radioSeccionTransversal;
    private javax.swing.JRadioButton radioSenalHorizontal;
    private javax.swing.JRadioButton radioSenalVertical;
    private javax.swing.JRadioButton radioSeparador;
    private javax.swing.JRadioButton radioSitioAccidentalidad;
    private javax.swing.JRadioButton radioSitioInestabilidad;
    private javax.swing.JRadioButton radioTipoTerreno;
    private javax.swing.JRadioButton radioTramo;
    private javax.swing.JRadioButton radioTunel;
    private javax.swing.JRadioButton radiodanoAfirmado;
    private javax.swing.JLabel resultIcon;
    private javax.swing.JLabel resultIcon1;
    private javax.swing.JLabel resultText;
    private javax.swing.JButton showShapeBtn;
    private javax.swing.JButton validateBtn;
    private javax.swing.JCheckBox validateMandatoryCheck;
    // End of variables declaration//GEN-END:variables
}
